<?php

namespace app\admin\controller;

use app\admin\service\MemberService;
use app\admin\validate\AdminValidate;
use common\controller\AdminAuthController;
use common\Token\Token;

/**
 * Class Member
 * @package app\admin\controller
 */
class Member extends AdminAuthController
{

    public function index()
    {
        $MemberService = MemberService::instance();
        $get = input_extract_rule([
            'page' => 1,
            'keywords' => '',
            'limit' => 20,
        ], 'get');
        AdminValidate::instance()->runCheck($get, '', __FUNCTION__);
        $data = $MemberService->getList($get);
        return $this->json_responce($data);
    }

    public function read()
    {
        $MemberService = MemberService::instance();
        $get = input_extract_rule([
            'id' => '',
        ], 'param');
        AdminValidate::instance()->runCheck($get, '', __FUNCTION__);
        $data = $MemberService->getByID($get['id']);
        return $this->json_responce($data);
    }

    public function save()
    {
        $MemberService = MemberService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $MemberService->createData($param);
        return $this->json_responce();
    }

    public function update()
    {
        $MemberService = MemberService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $MemberService->updateByID($param);
        return $this->json_responce();
    }

    public function delete()
    {
        $MemberService = MemberService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $MemberService->delByID($param);
        return $this->json_responce();
    }

    public function deletes()
    {
        $MemberService = MemberService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $MemberService->delByIDs($param);
        return $this->json_responce();
    }

    public function enables()
    {
        $MemberService = MemberService::instance();
        $param = $this->param;
        AdminValidate::instance()->runCheck($param, '', __FUNCTION__);
        $data = $MemberService->enableByIDs($param);
        return $this->json_responce();
    }

}
 